package com.qianyu.project.mapper.provider.gsl;

import com.qianyu.project.entity.InvoiceReceiveInfo;
import org.apache.ibatis.jdbc.SQL;

/**
 * @description 描述一下方法的作用
 * @date: $ $
 * @author: $
 * @return $
 */
public class InvoiceReceiveInfoMapperProvider {
    public String select(InvoiceReceiveInfo i){
        String sql=new SQL(){
            {
                SELECT("i.*,c.contract_name as cname,p.project_name as pname,o.open_company_name as oname,r.receive_company_name as rname");
                FROM("invoice_receive_info i,labor_contract c,project_info p,open_company o,receive_company r");
                WHERE("i.c_id=c.id and i.p_id=p.id and i.pay_company_id=o.id and i.income_company_id=r.id");
                if(i.getInvoiceNo()!=null && i.getInvoiceNo()!=""){
                    WHERE("i.invoice_no like '%${invoiceNo}%'");
                }
                if(i.getInvoiceAmount()!=null){
                    WHERE("i.invoice_amount >=#{invoiceAmount}");
                }
                if(i.getRname()!=null && i.getRname()!=""){
                    WHERE("i.invoice_amount <#{rname}");
                }
                if(i.getIncomeCompanyId()!=null){
                    WHERE("i.income_company_id =#{incomeCompanyId}");
                }
                if(i.getPayCompanyId()!=null){
                    WHERE("i.pay_company_id =#{payCompanyId}");
                }
                if(i.getEditer()!=null){
                    WHERE("i.editer like '%${editer}%'");
                }
                if(i.getComment()!=null){
                    WHERE("i.comment =#{comment}");
                }
                if(i.getPId()!=null){
                    WHERE("i.p_id =#{pId}");
                }

            }
        }.toString();
        return sql;
    }
    public String selectByid(String i){
        String sql=new SQL(){
            {
                SELECT("*");
                FROM("invoice_receive_info");
                WHERE("id="+i);
            }
        }.toString();
        return sql;
    }public String insert(InvoiceReceiveInfo i){
        String sql=new SQL(){
            {
                INSERT_INTO("invoice_receive_info");
                VALUES("id,p_id,c_id,open_type,pay_company_id,income_company_id,invoice_type,invoice_no,invoice_amount,amount_upper,account_bank,account_num,taxplayer_no,phone_address,editer,open_date,comment,attach_ids",
                        "null,#{pId},#{cId},#{openType},#{payCompanyId},#{incomeCompanyId},#{invoiceType},#{invoiceNo},#{invoiceAmount},#{amountUpper},#{accountBank},#{accountNum},#{taxplayerNo},#{phoneAddress},#{editer},#{openDate},#{comment},#{attachIds}");
            }
        }.toString();
        return sql;
    }public String delete(String i){
        String sql=new SQL(){
            {
                DELETE_FROM("invoice_receive_info");
                WHERE("id="+i);
            }
        }.toString();
        return sql;
    }public String update(InvoiceReceiveInfo i){
        String sql=new SQL(){
            {
                UPDATE("invoice_receive_info");
                SET("p_id=#{pId},c_id=#{cId},open_type=#{openType},pay_company_id=#{payCompanyId},income_company_id=#{incomeCompanyId},invoice_type=#{invoiceType},invoice_no=#{invoiceNo},invoice_amount=#{invoiceAmount},amount_upper=#{amountUpper},account_bank=#{accountBank},account_num=#{accountNum},taxplayer_no=#{taxplayerNo},phone_address=#{phoneAddress},editer=#{editer},open_date=#{openDate},comment=#{comment},attach_ids=#{attachIds}");
                WHERE("id=#{id}");
            }
        }.toString();
        return sql;
    }


}
